@extends('admin.frame_layout')
<?php $top_selected = "碎片管理";$page_menu = "碎片分类" ?>

@section('content')
    <div class="formbody">
        <div class="formtitle"><span>碎片分类信息编辑</span></div>
        <form action="{{route('admin.slugClassify.save',['id'=>(isset($classify)?($classify->id):0)])}}" method="post"
              id="admin">
            {!! csrf_field() !!}
            <ul class="forminfo">
                <li>
                    <label class="lable">父级分类</label>
                    <select name="parent" id="parent">
                        <option value="0">无父级分类</option>
                        @foreach($classifies as $i)
                            <option value="{{$i->id}}"
                                    {{isset($classify)?($classify->pid == $i->id ? "selected" : ""):""}}>
                                {{$i->title}}
                            </option>
                        @endforeach
                    </select>
                    <i for="cate">选择父级分类！</i>
                </li>

                {!! inputText("分类标识","slug","text",
                    isset($classify)?("$classify->slug"):(""),
                    "长度最好不超过20个字符！") !!}

                {!! inputText("分类名称","title","text",
                    isset($classify)?("$classify->title"):(""),
                    "长度最好不超过20个字符！") !!}

                {!! inputTextArea("分类描述","intro",
                    isset($classify)?("$classify->intro"):(""),
                    "注明分类的用途，方便使用！") !!}

                <li><label class="lable">&nbsp;</label>
                    <input type="submit" class="btn" value="确认保存"/>
                </li>
            </ul>
        </form>
    </div>
@endsection

@section('footer')
    <script type="text/javascript">
        $("#admin").validate({
            rules: {
                slug: {
                    required: true,
                    maxlength: 100
                },
                title: {
                    required: true,
                    maxlength: 100
                },
                intro: {
                    required: true,
                    maxlength: 255
                }
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("i[for='" + element.attr("id") + "']").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{route('admin.slug.classify')}}";
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection
